package com.company.Demo;

import java.util.Scanner;

public class LK6011 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] arr = new int[n][m];
        for(int i =0;i<n;i++){
            String a = scanner.nextLine();
            char[] nums = a.toCharArray();
            for(int j=0;j<m;j++){
               arr[i][j] = nums[j]=='0'?0:1;
            }
        }
        String s = scanner.nextLine();
        char[] chars = s.toCharArray();
        int x = 0;
        int y = 0;
        for(int i =0;i<chars.length;i++){
            if(chars[i]=='W'){
                if(x-1>=0&&arr[x-1][y]==0){
                    x--;
                }
            }else if(chars[i]=='S'){
                if(x+1<n&&arr[x+1][y]==0){
                    x++;
                }
            }else if(chars[i]=='A'){
                if(y-1>=0&&arr[x][y-1]==0){
                    y--;
                }
            }else{
                if(y+1<m&&arr[x][y+1]==0){
                    y++;
                }
            }
        }
        x++;
        y++;
        System.out.println(x+" "+y);
//         3 3 7
//         000
//         110
//         000
//         SDWDSSA
    }


}
